package com.shuhua.taskServer.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shuhua.pojo.entity.TaskOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

@Mapper
public interface TaskOrderMapper extends BaseMapper<TaskOrder> {
    @Select("SELECT o.*, t.*, c.username as craftsman_username, c.phone as craftsman_phone, c.real_name as craftsman_real_name, c.department as craftsman_department, c.station as craftsman_station, c.avatar as craftsman_avatar FROM task_order o LEFT JOIN task t ON o.task_id = t.task_id LEFT JOIN craftsman c ON o.craftsman_id = c.id WHERE o.craftsman_id = #{craftsmanId}")
    List<Map<String, Object>> selectOrderWithTaskByCraftsmanId(@Param("craftsmanId") Long craftsmanId);

    @Select("SELECT o.*, t.*, c.username as craftsman_username, c.phone as craftsman_phone, c.real_name as craftsman_real_name, c.department as craftsman_department, c.station as craftsman_station, c.avatar as craftsman_avatar FROM task_order o LEFT JOIN task t ON o.task_id = t.task_id LEFT JOIN craftsman c ON o.craftsman_id = c.id WHERE o.task_id = #{taskId} AND o.craftsman_id = #{craftsmanId} LIMIT 1")
    Map<String, Object> selectOrderWithTaskByTaskAndCraftsman(@Param("taskId") Long taskId, @Param("craftsmanId") Long craftsmanId);

    @Select("SELECT o.*, t.*, c.username as craftsman_username, c.phone as craftsman_phone, c.real_name as craftsman_real_name, c.department as craftsman_department, c.station as craftsman_station, c.avatar as craftsman_avatar FROM task_order o LEFT JOIN task t ON o.task_id = t.task_id LEFT JOIN craftsman c ON o.craftsman_id = c.id")
    List<Map<String, Object>> selectAllOrderWithTask();
} 